// properties parser

module.exports = (function() {
    var Properties = function Properties(content) {
        var v = Object.create(Properties);
        content = content.split("\n");
        content.forEach(function self(i, index) {
            if(i.startsWith("#") || i.trim() == "") return;
            i = i.trim().split("=");
            if(i.length < 2) throw new SyntaxError("Properties file syntax error at line " + (index + 1));
            v.put(i[0], i.slice(1).join("="));
        });
        return v;
    }
    Properties.put = function(name, value) {
        this.map[name] = value;
    }
    Properties.get = function(name, def) {
        if(name in this.map) return this.map[name];
        return def;
    }
    Properties.ensure = function(name, value) {
        if(!name in this.map) this.map[name] = value;
    }
    Properties.map = {};
    Properties.toString = function() {return "[Properties]";}
    return Properties;
})();
